<!--
  在web项目中访问静态资源 由 一个叫做defaultServlet的类型来进行处理
-->

<html>
<head>
    <!-- 设置html页面的编码   -->
    <meta charset="UTF-8">
</head>
<body>
<h2></h2>

<button id="addBt">添加</button>
<button id="updateBt">修改</button>
<button id="delBt">删除</button>
<button id="getByIdBt">通过id查询</button>
<button id="pageBt">分页查询</button>

<script src="https://unpkg.com/axios/dist/axios.js"></script>
<script>

    // axios({
    //     method: 'POST',
    //     url: 'http://localhost:8080/emp/update',
    //     data: {"empno":1001,"ename":"zhansgan","age":20}
    // }).then(res=>{
    //     console.log(res.data);
    // })

    //添加请求

    function add(){
        axios({
            method: 'post',
            url: 'http://localhost:8080/business',
            data: {
                "businessAccount": "dhsjkhdask",
                "businessName": "美味小吃",
                "businessAddress": "新乡市",
                "businessExplain": "好吃不贵",
                "businessImg" : "",
                "startPrice": 18,
                "deliveryPrice": 8,
                "remarks": ""
            }
        }).then(res=>{
            console.log(res.data);
        })
    }

    function update(){
        axios({
            method: 'put',
            url: 'http://localhost:8080/business',
            data: {
                "businessId": 1002,
                "businessAccount": "dhsjkhdask",
                "businessName": "美味小吃",
                "businessAddress": "新乡市",
                "businessExplain": "好吃不贵",
                "businessImg" : "",
                "startPrice": 18,
                "deliveryPrice": 8,
                "remarks": ""
            }
        }).then(res=>{
            console.log(res.data);
        })
    }

    function del(){
        axios({
            method: 'delete',
            url: 'http://localhost:8080/business/1004',
        }).then(res=>{
            console.log(res.data);
        })
    }

    function getById(){
        axios({
            method: 'get',
            url: 'http://localhost:8080/business/1004',
        }).then(res=>{
            console.log(res.data);
        })
    }

    function getByPage(){
        axios({
            method: 'post',
            url: 'http://localhost:8080/business/page',
            data: {
                "pageNow": 1,
                "pageCount": 6,
                "businessName": "奶茶",
                "businessAddress": "新乡"
            }
        }).then(res=>{
            console.log(res.data);
        })
    }

    document.getElementById("addBt").onclick = function (){
        add();
    }

    document.getElementById("updateBt").onclick = function (){
        update();
    }

    document.getElementById("delBt").onclick = function (){
        del();
    }

    document.getElementById("getByIdBt").onclick = function (){
        getById();
    }

    document.getElementById("pageBt").onclick = function (){
        getByPage();
    }
</script>

</body>
</html>

